//
//  HomeViewController.m
//  SG
//
//  Created by FISH on 2018/4/18.
//  Copyright © 2018年 yimindai. All rights reserved.
//

#import "HomeViewController.h"
#import "MDMultipleSegmentViewCell.h"
@interface HomeViewController ()<MDFlipCollectionViewDelegate>
//@property (strong, nonatomic) MDMultipleSegmentView *segView;
@property (strong, nonatomic) MDFlipCollectionView *collectView;
@property (strong, nonatomic) MDMultipleSegmentViewCell *SegmentViewCell;
@property (weak, nonatomic) IBOutlet UIView *NaView;
@property (weak, nonatomic) IBOutlet UIButton *leftBtn;
@property (weak, nonatomic) IBOutlet UIButton *rightBtn;
@property (weak, nonatomic) IBOutlet UILabel *contentLab;

@property (strong, nonatomic) UIButton *selectedBtn;

@end

@implementation HomeViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = KWhiteColor;
    
    [self createHomeViewControllerUI];
    
//    [self gIFloadMethods];
}

- (void)createHomeViewControllerUI
{
    [self createNaViewUI];

    [self createSearchViewUI];
    
    [self createMDSegmentUI];
}

-(void)createMDSegmentUI
{
    NSArray *segmentButtonArray = @[@"情感",@"健身",@"瑜伽",@"美容"];
    UIView *segmentView = [[UIView alloc]initWithFrame:CGRectMake(0, _SView.frame.origin.y+_SView.frame.size.height, kScreenWidth, 44)];
    segmentView.backgroundColor = KWhiteColor;
    for(int i=0;i<4;i++)
    {
        UIButton *segmentButton = [[UIButton alloc]initWithFrame:CGRectMake(kScreenWidth/4*i, 0, kScreenWidth/4, segmentView.frame.size.height)];
        [segmentButton setTitle:StringFormat(@"%@",segmentButtonArray[i]) forState:UIControlStateNormal];
        segmentButton.titleLabel.font = FONT14;
        segmentButton.tag = i;
        if(i == 0){
            [segmentButton setTitleColor:KRedColor forState:UIControlStateNormal];
            _selectedBtn = segmentButton;
        }
        else{
            [segmentButton setTitleColor:KBlackColor forState:UIControlStateNormal];
        }
        [segmentButton addTarget:self action:@selector(tosegmentButton:) forControlEvents:UIControlEventTouchUpInside];
        [segmentView addSubview:segmentButton];
    }
    [self.view addSubview:segmentView];
}

-(void)tosegmentButton:(UIButton*)sender
{
    if (_selectedBtn) {
        [_selectedBtn setTitleColor:KBlackColor forState:UIControlStateNormal];
    }
    _selectedBtn = sender;
    [_selectedBtn setTitleColor:KRedColor forState:UIControlStateNormal];
}

- (UIViewController *)controller
{
    UIViewController *vc = [[UIViewController alloc] init];
    CGFloat red = arc4random() / (CGFloat)INT_MAX;
    CGFloat green = arc4random() / (CGFloat)INT_MAX;
    CGFloat blue = arc4random() / (CGFloat)INT_MAX;
    vc.view.backgroundColor = [UIColor colorWithRed:red green:green blue:blue alpha:1.0];
    return vc;
}




#pragma createSearchViewUI
- (void)createSearchViewUI
{
    _SView.frame = CGRectMake(0, kNavHeight, kScreenWidth, 50);
    _messageBtn.frame = CGRectMake(kScreenWidth-70, 10, 70, 30);
    [_messageBtn addTarget:self action:@selector(toMessageRemind) forControlEvents:UIControlEventTouchUpInside];
    
    _SMView.frame = CGRectMake(20, 9, kScreenWidth-90, 32);
    _SMView.layer.cornerRadius = _SMView.frame.size.height/2;
    _SMView.clipsToBounds = YES;
    
    _search = [[SearchView alloc]initWithFrame:CGRectMake(20, 0, _SMView.frame.size.width-30, _SMView.frame.size.height)];
    [_search createSearchView:@"搜索想要的关键词"];
    _search.delegate = self;
    [_SMView addSubview:_search];
}

#pragma createNaViewUI
- (void)createNaViewUI
{
    _NaView.frame = CGRectMake(0, 0, kScreenWidth, kNavHeight);
    _leftBtn.frame = CGRectMake(10, kNavY+(44-30)/2, 30, 30);
    _rightBtn.frame = CGRectMake(kScreenWidth-40, kNavY+(44-30)/2, 30, 30);
    
    _contentLab.frame = CGRectMake(40, kNavY+(44-30)/2, kScreenWidth-80, 30);
    _leftBtn.titleLabel.font = FONTONE;
    [_leftBtn addTarget:self action:@selector(toCancel) forControlEvents:UIControlEventTouchUpInside];
    _rightBtn.titleLabel.font = FONTONE;
    [_rightBtn addTarget:self action:@selector(toDynamic) forControlEvents:UIControlEventTouchUpInside];
    _contentLab.font = FONTTHRE;
    _contentLab.text = @"登录搜缘";
#pragma 按钮设置图片在上文字在下
    [self setButtonImageUpLableDown:_rightBtn AndCGFloat:0];
}


//- (void)gIFloadMethods
//{
//    _ImgView.frame = CGRectMake(0, 0, kScreenWidth, kScreenWidth-kTabBarHeight);
//    _ImgView.contentMode = UIViewContentModeScaleToFill;
//    _ImgView.clipsToBounds = YES;
//
//    NSData *imageData = [NSData dataWithContentsOfURL:[NSURL URLWithString:@"https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1524114508875&di=b4f00a20337bcadb204731235b949ed3&imgtype=0&src=http%3A%2F%2Fimg.zcool.cn%2Fcommunity%2F012c7555f6e4ed32f875a1320f1b07.gif"]];
//    _ImgView.image = [UIImage sd_animatedGIFWithData:imageData];
//}

- (void)toDynamic
{
    DLog(@"动态");
}

-(void)toMessageRemind
{
    DLog(@"消息");
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
